/******************************************************************************
 * Filename : uc_time.h
 * Copyright:
 * Created  : 2011-1-6 by franco.yin
 * Description -
 *
 ******************************************************************************/

#ifndef _UC_TIME_H
#define _UC_TIME_H

#ifdef __cplusplus
extern "C" {
#endif

#include "uc_public.h"

#define uctime_s struct timeval
#define uctime_sec_s time_t

#define uctime_sec(pTime) ((pTime)->tv_sec)
#define uctime_usec(pTime) ((pTime)->tv_usec)
#define uctime_msec(pTime) ((short)(((pTime)->tv_usec) / 1000))

#define uctime_get(pTime) gettimeofday(pTime, NULL)
#define uctime_get_sec(pTime) time(pTime)

typedef struct _uctime_date{
	int year;
	int month;
	int day;
	int hour;
	int min;
	int sec;
	int msec;
	int usec;
}uctime_date_s;

extern int uctime_get_diff(uctime_s *t_start, uctime_s *t_end);
extern void uctime_copy(uctime_s *t_dst, uctime_s *t_src);
extern void uctime_set(uctime_s *pTime, int sec, short msec);
extern int uctime_uptime_sec();
extern UC_S64 uctime_uptime_msec();
extern char *uctime_str_by_time(uctime_s *pTime, char *format, char *dst, int if_ms);
extern char *uctime_str_by_sec(uctime_sec_s sec, char *format, char *dst);
extern char *uctime_sec_to_str(uctime_sec_s sec, char *dst);
extern char *uctime_str_now(char *format, char *dst, int if_ms);
extern uctime_sec_s uctime_str_to_sec(char * szTime);
extern int uctime_time_to_ucdate(uctime_s *pTime, uctime_date_s *pDate);
extern uctime_sec_s uctime_date_to_sec(uctime_date_s *pDate);
extern uctime_sec_s uctime_close_str_to_sec(char * szTime);
extern int uctime_get_date_and_ucdate(uctime_s *pTime, uctime_date_s *pDate);
extern int uctime_check_timeout(UC_S64 *pTtimer, UC_S64 now_time, int timeout_ms);
extern double uctime_date_to_double(uctime_s *pTime);

#ifdef __cplusplus
}
#endif

#endif
